package cn.vin.demo;

import javax.validation.constraints.NotNull;
import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.util.Date;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class Demo {
    public Demo() {
        System.out.println("demo");
    }

    public static void main(String[] args) throws Exception {
        /*Instant now = Instant.now();
        Duration between = Duration.between(now, now.plusMillis(1000));
        Period between1 = Period.between(LocalDate.of(1994, 1, 1),LocalDate.now());
        System.out.println(between.getSeconds());
        System.out.println(between1.getDays());*/
//        Duration duration = Duration.between(LocalDateTime.of(1994,Month.JULY,23,1,1),LocalDateTime.now());
//        System.out.println(duration.getSeconds() / Duration.ofDays(1).getSeconds());
//        System.out.println(Period.ofMonths(1).getMonths());
//        System.out.println(LocalDate.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.MONDAY)));
//        System.out.println(Instant.now().get(ChronoField.DAY_OF_MONTH));
        /*LocalDate.now().with(temporal -> {
            temporal.get(ChronoField.DAY_OF_WEEK);
            if(dow == DayOfWeek.FRIDAY)
            return temporal.plus(1, ChronoUnit.DAYS);
        });*/
//        System.out.println(DayOfWeek.of(LocalDate.now().minusDays(1).get(ChronoField.DAY_OF_WEEK)).getValue());
        /*DateTimeFormatter d1 = DateTimeFormatter.ofPattern("d. MMMM yyyy", Locale.JAPAN);
        DateTimeFormatter d3 = DateTimeFormatter.ofPattern("d. MMMM yyyy", Locale.KOREA);
        LocalDate now = LocalDate.now();
        System.out.println(now.format(d1));
        System.out.println(now.format(d3));*/
//        LocalDateTime now = LocalDateTime.now();
//        ZoneId sh = TimeZone.getDefault().toZoneId();
//        ZoneId rome = ZoneId.of("Europe/Rome");
//        System.out.println(now.toInstant(ZoneOffset.UTC));
//        System.out.println(now.toInstant(ZoneOffset.MIN));
//        System.out.println(LocalDate.now());
//        System.out.println(JapaneseDate.now());
//        System.out.println(MinguoDate.now());
//        System.out.println(HijrahDate.now());
//        System.out.println(ThaiBuddhistDate.now());
//        Maps.uniqueIndex(Lists.newArrayList(1,2),o -> o);
        /*Instant instant =
                LocalDate.now().atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
        Instant instant1 = new Date().toInstant();
        System.out.println(instant1);
        System.out.println(instant1.compareTo(instant));*/
//        System.out.println(LocalDate.now().toString());
        /*CustomLog binLog = new CustomLog();
        binLog.setOpenid("sdf");
        binLog.setUserId(1L);
        binLog.setBaseType(1);
        String s = JSONObject.toJSONString(binLog);
        CustomLog customLog = JSONObject.parseObject(s, CustomLog.class);*/
        /*int start = 0;
        fun(start,start +=100);
        System.out.println(start);*/
//        System.out.println(Integer.MAX_VALUE);
        /*String[] strings = Stream.of("a", "b").toArray(new IntFunction<String[]>() {
            @Override
            public String[] apply(int value) {
                return new String[value];
            }
        });
        System.out.println(strings.length);*/
//        System.out.println(Demo.class.getClassLoader().getResource(""));
        /*InputStream is = Demo.class.getClassLoader().getResourceAsStream("a.json");
        JSONObject jb = JSONObject.parseObject(Objects.requireNonNull(is), JSONObject.class);
        is.close();
        System.out.println(jb.getJSONObject("1").getString("1"));*/
       /* List<String> strings = Arrays.asList("a", "b", "c", "d", "e", "f", "g");
        Map<Integer,String> test = Arrays.asList(1, 2, 3, 1, 4, 2, 3).stream().collect(Collectors.toMap(o -> o, o -> strings.get(i++), (s, s2) -> s2, HashMap::new));
        System.out.println(test);*/
//        System.out.println(Arrays.asList(1,3,1,3).stream().collect(Collectors.toSet()));
        /*List<Integer> list = Stream.iterate(0, n -> n + 1).limit(48).collect(Collectors.toList());
        List<List<Integer>> collect = Stream.iterate(0, n -> n + 1).limit(10).map(o ->
                list.stream().skip(o * 5).limit(5).collect(Collectors.toList())
        ).collect(Collectors.toList());

        List<List<Integer>> collect2 = Stream.iterate(0, n -> n + 1).limit(10).parallel().map(o ->
                list.stream().skip(o * 5).limit(5).parallel().collect(Collectors.toList())
        ).collect(Collectors.toList());
        System.out.println(collect);
        System.out.println(collect2);
        System.out.println(Lists.partition(list,5));*/
        /*String s = "{\"1\":{\"0\":72,\"1\":92,\"2\":116,\"3\":274,\"4\":178,\"5\":8},\"2\":{\"1\":17,\"2\":8,\"3\":4,\"4\":4,\"5\":0},\"3\":{\"1\":9,\"2\":220,\"3\":305}}";
        Map<String,Map<String,Integer>> map = JSONObject.parseObject(s,Map.class);
        System.out.println(map.get("1").get("0"));*/
//        Class<?> clazz = Demo.class.getClassLoader().loadClass("cn.vin.demo.Demo4");
//        Class<?> clazz =Class.forName("cn.vin.demo.Demo4",false,Demo.class.getClassLoader());
//        Class.forName()
//        System.out.println(clazz.getField("a").getInt(clazz));
        System.out.println("1".equals(null));
    }



    public static class CustomLog {
        private String gameId;
        @NotNull
        private Integer baseType;
        @NotNull
        private String openid;
        @NotNull
        private Long userId;
        @NotNull
        private Integer subType;
        private String extra;
        private Integer extraMark;
        private Date gmtCreate;

        @Override
        public String toString() {
            return "CustomLog{" +
                    "gameId='" + gameId + '\'' +
                    ", baseType=" + baseType +
                    ", openid='" + openid + '\'' +
                    ", userId=" + userId +
                    ", subType=" + subType +
                    ", extra='" + extra + '\'' +
                    ", extraMark=" + extraMark +
                    '}';
        }

        public String getGameId() {
            return gameId;
        }

        public void setGameId(String gameId) {
            this.gameId = gameId;
        }

        public Integer getBaseType() {
            return baseType;
        }

        public void setBaseType(Integer baseType) {
            this.baseType = baseType;
        }

        public String getOpenid() {
            return openid;
        }

        public void setOpenid(String openid) {
            this.openid = openid;
        }

        public Long getUserId() {
            return userId;
        }

        public void setUserId(Long userId) {
            this.userId = userId;
        }

        public Integer getSubType() {
            return subType;
        }

        public void setSubType(Integer subType) {
            this.subType = subType;
        }

        public String getExtra() {
            return extra;
        }

        public void setExtra(String extra) {
            this.extra = extra;
        }

        public Integer getExtraMark() {
            return extraMark;
        }

        public void setExtraMark(Integer extraMark) {
            this.extraMark = extraMark;
        }

        public Date getGmtCreate() {
            return gmtCreate;
        }

        public void setGmtCreate(Date gmtCreate) {
            this.gmtCreate = gmtCreate;
        }
    }

    public static <T> void copy(T t1, T t2) throws Exception {
        Class<?> aClass = t1.getClass();
        Field[] srcFields = aClass.getDeclaredFields();
        for(Field f : srcFields) {
            f.setAccessible(true);
            Object v2 = f.get(t2);
            if(v2 == null) {
                f.set(t2,f.get(t1));
            }
        }
    }

    static class People implements Comparable<People> {
        Integer id;
        private Integer age;
        public People(Integer id, Integer age) {
            this.id = id;
            this.age = age;
            System.out.println("people");
        }

        public People() {
        }

        Demo demo = new Demo();

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            People people = (People) o;
            return id.equals(people.id);
        }

        @Override
        public int hashCode() {
            return Objects.hash(id);
        }

        @Override
        public int compareTo(People o) {
            if(this.getId().equals(o.getId())) {
                return 0;
            }
            return this.age > o.getAge() ? 1 : -1;
        }

        @Override
        public String toString() {
            return "People{" +
                    "id=" + id +
                    ", age=" + age +
                    '}';
        }
    }
}
